<template>
  <div>


    <basic-container>
      <vue-element-loading :active="isActive" spinner="bar-fade-scale" color="#409eff" background-color="rgba(255,255,255,0.2)"/>
      <el-form :inline="true" :model="formReport" >
        <div style="margin-top: 22px">
          <el-form-item>
            <el-input v-model="formReport.account" clearable placeholder="账号"></el-input>
          </el-form-item>

          <el-form-item>
            <el-button icon="el-icon-search" type="primary"  @click="onLoad">查询</el-button>
          </el-form-item>

        </div>
      </el-form>
      <el-row>
        <el-col :span="24">
          <template>
            <el-table
              :data="tableData"
              style="width: 100%">
              <el-table-column
                prop="account"
                label="账号">
              </el-table-column>
              <el-table-column
                prop="loginIp"
                label="登录IP">
              </el-table-column>
              <el-table-column
                prop="deviceImei"
                label="登录设备ID">
              </el-table-column>
              <el-table-column
                prop="createTime"
                label="登录时间">
                <template slot-scope="scope">
                  {{scope.row.createTime  | formatDate('YYYY-MM-DD HH:mm:ss')}}
                </template>
              </el-table-column>
              <el-table-column
                width="200"
                label="操作">
                <template slot-scope="scope" align="center">
                  <div>
                    <el-button @click="addWhite(scope.row)" type="text" size="medium">加入登录白名单</el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page.currentPage"
            :page-sizes="[10, 20, 50, 100, 200]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.total">
          </el-pagination>
        </el-col>
      </el-row>

    </basic-container>
  </div>
</template>

<script>

import {mapGetters} from "vuex";
import VueElementLoading from 'vue-element-loading'
import {
  loginWhiteDevice,
  addLoginWhite
} from "@/api/game/gameDeposit";
export default {
  name: "headman",

  data() {
    return {
      isActive: false,
      fullscreenLoading: false,
      formReport: {
        account:'',
        devices:''
      },
      page: {
        currentPage: 1,
        pageSize: 20,
        total: '',
      },
      totalCount:'',
      tableData:[],
      tableTotal:{}
    };

  },
  components: {
    VueElementLoading
  },
  created() {
    this.onLoad()
  },
  methods: {
    addWhite(item) {
      this.$confirm("确定要将该设备加入白名单吗？", '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        addLoginWhite(item).then(res => {
          if (res.data.success) {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.onLoad();
          } else {
            this.$message({
              type: "error",
              message: res.data.msg
            });
          }
        })
      }).catch(() => {


      });
    },
    isNotEmpty(arr) {
      return arr != null && arr.length !== 0
    },
    onLoad(){
      this.isActive = true;
      loginWhiteDevice(this.page.currentPage, this.page.pageSize, Object.assign(this.formReport)).then(res => {
        const data = res.data.data;
        console.log("res.data.data", res.data.data)
        this.page.total = data.total;
        this.tableData = data.records;
        this.isActive = false;
      })
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.onLoad();
    },
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.onLoad();
    }
  }
};
</script>

<style lang="scss" >

</style>
